import java.io.PrintStream;
import java.util.Random;; 
public class Tapis {
	private static PrintStream output; 
	private static Random generator=new Random(); 
	private static int taille=20; 
	private static double midtaille=(taille+0.0)/2; 
	public static void main(String[] args) {
		double[][][] coordX=new double[taille][taille][taille];
		double[][][] coordY=new double[taille][taille][taille];
		double[][][] coordZ=new double[taille][taille][taille];
		for(int i=0;i<taille;i++){
			for(int j=0;j<taille;j++){
				for(int k=0;k<taille;k++){
				coordX[i][j][k]=((generator.nextDouble()/2+0.166*(Math.sin((i+0.0)/17*Math.PI)+Math.sin((j+0.0)/13*Math.PI)+Math.sin((k+0.0)/23*Math.PI))))/2.0-0.5; 	
				coordY[i][j][k]=((generator.nextDouble()/2+0.166*(Math.sin((i+0.0)/13*Math.PI)+Math.sin((j+0.0)/21*Math.PI)+Math.sin((k+0.0)/13*Math.PI))))/2.0-0.5; 	
				coordZ[i][j][k]=((generator.nextDouble()/2+0.166*(Math.sin((i+0.0)/21*Math.PI)+Math.sin((j+0.0)/17*Math.PI)+Math.sin((k+0.0)/17*Math.PI))))/2.0-0.5; 	
				}// for k
			}//for j
			
		}// for i
		
		
		
		try{
			
		output=new PrintStream("/tmp/grid.txt"); 
		
		for(int i=0;i<taille;i++){
			for(int j=0;j<taille;j++){
				for(int k=0;k<taille;k++){
				String couleur[]={"Blue","Red","Yellow","Green","Blue"}; 
				//String	s="object{dodecahedron() scale 0.25  rotate<"+ generator.nextInt(360)+","+generator.nextInt(360)+","+generator.nextInt(360)+"> translate<"+(i-midtaille+coordX[i][j][k])+","+(j-midtaille+coordY[i][j][k])+","+(k-midtaille+coordZ[i][j][k])+">  texture{pigment{"+couleur[generator.nextInt(5)]+"}} finish{reflection 0.7}}";
				String s="sphere{<"+(i-midtaille+coordX[i][j][k])+","+(j-midtaille+coordY[i][j][k])+","+(k-midtaille+coordZ[i][j][k])+">,0.25  texture{pigment{"+couleur[generator.nextInt(5)]+"}}finish{reflection 0.7}}";
				System.out.println(s); 
				output.println(s); 
				if(i!=0){
					String c1="cylinder{<"+( i-1.0-midtaille+coordX[i-1][j][k])+","+(j-midtaille+coordY[i-1][j][k])+","+(k-midtaille+coordZ[i-1][j][k])+">,<"+( i-midtaille+coordX[i][j][k]    )+","+(j-midtaille+coordY[i][j][k] )+","+( k-midtaille+coordZ[i][j][k])+">,0.02 "; 
					c1+="texture{T_Copper_2C} finish{Metallic_Finish}}"; 
					System.out.println(c1);
					output.println(c1); 
				}// if i
				if(j!=0){
					String c2="cylinder{<"+( i-midtaille+coordX[i][j-1][k])+","+(j-1.0-midtaille+coordY[i][j-1][k])+","+(k-midtaille+coordZ[i][j-1][k])+">,<"+( i-midtaille+coordX[i][j][k]    )+","+(j-midtaille+coordY[i][j][k] )+","+( k-midtaille+coordZ[i][j][k])+">,0.02 "; 

					c2+="texture{T_Copper_2C} finish{Metallic_Finish}}"; 
					System.out.println(c2);
					output.println(c2);
				}// if j
				
				if(k!=0){
					String c3="cylinder{<"+( i-midtaille+coordX[i][j][k-1])+","+(j-midtaille+coordY[i][j][k-1])+","+(k-1.0-midtaille+coordZ[i][j][k-1])+">,<"+( i-midtaille+coordX[i][j][k]    )+","+(j-midtaille+coordY[i][j][k] )+","+( k-midtaille+coordZ[i][j][k])+">,0.02 "; 

					c3+="texture{T_Copper_2C} finish{Metallic_Finish}}"; 
					System.out.println(c3);
					output.println(c3);
				}// if j
				
				
				
				}//for k
			}// for j
		}// for i
		
		}
		catch(Exception e){System.out.println("plante "+e); }
		
	}

}
